package com.king.pattem.guardedsuspension;

/**
 * @author taomk
 * @version 1.0
 * @since 15-2-3 下午9:39
 */
public class ServerThread extends Thread {

	private RequestQueue requestQueue;

	public ServerThread(RequestQueue requestQueue, String name) {
		super(name);
		this.requestQueue = requestQueue;
	}

	@Override
	public void run() {
		try {
			while (true) {
				// 得到请求
				final Request request = requestQueue.getRequest();
				// 模拟处理请求耗时
				Thread.sleep(100);
				System.out.println(Thread.currentThread().getName() + " handles " + request.getName());
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
